

import java.util.Vector;

import org.metacsp.meta.symbolsAndTime.EarliestStartTimeVarOH;

import meta.symbolsAndTime.SAUNA.Map;
import meta.symbolsAndTime.SAUNA.TemporalPolyhedronScheduler;
import multi.SAUNA.Path;
import multi.SAUNA.TemporalPolyhedronNetworkSolver;

import org.metacsp.multi.spatial.rectangleAlgebra.Point;
import org.metacsp.framework.ConstraintNetwork;
import org.metacsp.framework.ValueOrderingH;
import org.metacsp.framework.VariableOrderingH;

public class TestTemporalPolyhedronScheduler {

	public static void main(String[] args) {
		
		//vehicle geometry
		double dimX = 1, dimY = 0.5;

		//Scheduler
		TemporalPolyhedronScheduler metaSolver = new TemporalPolyhedronScheduler(0,200000,0);
		//this is the temporal solver underneath the scheduler
		TemporalPolyhedronNetworkSolver groundSolver = (TemporalPolyhedronNetworkSolver)metaSolver.getConstraintSolvers()[0];
		
		//Most critical conflict is the earliest one
		VariableOrderingH varOH = new EarliestStartTimeVarOH();
		//VariableOrderingH varOH = new LatestStartTimeVarOH();
		
		//Do nothing, as this is already done in the Map metaConstraint.
		ValueOrderingH valOH = null;
		
		//Load the map from file and use it as a domain feature for the scheduler
		Map map = new Map("SAUNA/TampraEmpty.map", varOH, valOH);
		metaSolver.addMetaConstraint(map);
		
		Vector<Path> paths = new Vector<Path>();
		paths.add(new Path("Vehicle A", "SAUNA/tampraH1.txt", new Point(0,0), map, 0.05, 5));
		paths.add(new Path("Vehicle B", "SAUNA/tampraH2.txt", new Point(0,0), map, 0.05, 5));
		paths.add(new Path("Vehicle C", "SAUNA/tampraH3.txt", new Point(0,0), map, 0.05, 5));
		
		//Make variables
		for (Path p : paths) {
			if (p.createConvexPolyhedra(groundSolver, dimX, dimY, 1, 0.1, 0.7, 0.8) == null) {
				System.out.println("FAILED TO CREATE POLYS FOR " + p.getName());
				System.exit(0);
			}
		}
		
		ConstraintNetwork.draw(groundSolver.getConstraintNetwork());
		
		//Draw consistency feature
		map.draw(groundSolver.getConstraintNetwork());
		//map.animate();

		System.out.println(metaSolver.getDescription());
		System.out.println(map.getDescription());

	}
}

